package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.PcbaLine;
import com.sailfish.springbootdemo.service.db1.PcbaLineService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@CrossOrigin
@RequestMapping("/pcbaLine")
public class PcbaLineController {

    @Autowired
    private PcbaLineService pcbaLineService;

    @PostMapping("/getAllPcbaLine")
    public Result getAllPcbaLine(String searchPcbaLineName, Integer pcbaCompanyId, Integer pcbaWorkshopId, Integer pcbaProcessId, Integer status, Integer paramsStatusDeclare, Integer paramsStatusActual, Integer paramsStatusBase, Integer page, Integer pageSize) {
        return pcbaLineService.getAllPcbaLine(searchPcbaLineName, pcbaCompanyId, pcbaWorkshopId, pcbaProcessId, status, paramsStatusDeclare, paramsStatusActual, paramsStatusBase, page, pageSize);
    }

    @PostMapping("/getAllPcbaLineForBaseLineCapacity")
    public Result getAllPcbaLineForBaseLineCapacity(String searchPcbaLineName, Integer pcbaCompanyId, Integer pcbaWorkshopId, Integer pcbaProcessId) {
        return pcbaLineService.getAllPcbaLineForBaseLineCapacity(searchPcbaLineName, pcbaCompanyId, pcbaWorkshopId, pcbaProcessId);
    }

    @PostMapping("/getAllPcbaLineForTechLineCapacity")
    public Result getAllPcbaLineForTechLineCapacity(String searchPcbaLineName, Integer pcbaCompanyId, Integer pcbaWorkshopId, Integer pcbaProcessId) {
        return pcbaLineService.getAllPcbaLineForTechLineCapacity(searchPcbaLineName, pcbaCompanyId, pcbaWorkshopId, pcbaProcessId);
    }

    @PostMapping("/getAllSmtLineByCompanyAndWorkshop")
    public Result getAllSmtLineByCompanyAndWorkshop(Integer pcbaCompanyId, Integer pcbaWorkshopId) {
        return pcbaLineService.getAllSmtLineByCompanyAndWorkshop(pcbaCompanyId, pcbaWorkshopId);
    }

    @PostMapping("/getAllPcbaLineWithAuditDevice")
    public Result getAllPcbaLineWithAuditDevice(String searchPcbaLineName, Integer pcbaCompanyId, Integer pcbaWorkshopId, Integer pcbaProcessId, Integer status, Integer paramsStatus) {
        return pcbaLineService.getAllPcbaLineWithAuditDevice(searchPcbaLineName, pcbaCompanyId, pcbaWorkshopId, pcbaProcessId, status, paramsStatus);
    }

    @PostMapping("/getAllPcbaLineView")
    public Result getAllPcbaLineView(@RequestBody String data) {
        return pcbaLineService.getAllPcbaLineView(data);
    }

    @PostMapping("/deleteById")
    public Result deleteById(Integer pcbaLineId) {
        return pcbaLineService.deleteById(pcbaLineId);
    }

    @PostMapping("/addOrUpdatePcbaLine")
    public Result addOrUpdatePcbaLine(@RequestBody String data) {
        return pcbaLineService.addOrUpdatePcbaLine(data);
    }

    @PostMapping("/addPcbaDeviceResourceOfLine")
    public Result addPcbaDeviceResourceOfLine(@RequestBody String data) {
        return pcbaLineService.addPcbaDeviceResourceOfLine(data);
    }

    @PostMapping("/judgeLineNameIsExist")
    public Result judgeLineNameIsExist(Integer pcbaCompanyId, Integer pcbaWorkshopId, Integer pcbaProcessId) {
        return pcbaLineService.judgeLineNameIsExist(pcbaCompanyId, pcbaWorkshopId, pcbaProcessId);
    }

    @PostMapping("/createLineListByProcess")
    public Result createLineListByProcess(Integer pcbaProcessId) {
        return pcbaLineService.createLineListByProcess(pcbaProcessId);
    }

    @PostMapping("/createLineListByProcesses")
    public Result createLineListByProcesses(String pcbaProcessIds) {
        return pcbaLineService.createLineListByProcesses(pcbaProcessIds);
    }

    @PostMapping("/getPcbaLineById")
    public Result getPcbaLineById(Integer pcbaLineId) {
        try {
            if (pcbaLineId == null || "".equals(pcbaLineId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaLineId", "Miss Param pcbaLineId", null);
            }
            return ResultUtil.success(pcbaLineService.getPcbaLineById(pcbaLineId));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/updateLineLevel")
    public Result updateLineLevel(Integer pcbaLineLevel, Integer pcbaLineId) {
        return pcbaLineService.updateLineLevel(pcbaLineLevel, pcbaLineId);
    }

    @PostMapping("/updateLineNotes")
    public Result updateLineNotes(String notes, Integer pcbaLineId) {
        return pcbaLineService.updateLineNotes(notes, pcbaLineId);
    }

    @PostMapping("/exportBaseCapacityExcel")
    public Result exportBaseCapacityExcel(String pcbaLineIds) {
        return pcbaLineService.exportBaseCapacityExcel(pcbaLineIds);
    }

    @PostMapping("/exportBaseCapacityExcelV2")
    public Result exportBaseCapacityExcelV2(String pcbaLineIds) {
        return pcbaLineService.exportBaseCapacityExcelV2(pcbaLineIds);
    }

    @PostMapping("/exportBaseCapacityExcelV3")
    public Result exportBaseCapacityExcelV3(String pcbaLineIds) {
        return pcbaLineService.exportBaseCapacityExcelV3(pcbaLineIds);
    }

    @PostMapping("/exportTechCapacityExcel")
    public Result exportTechCapacityExcel(String pcbaLineIds) {
        return pcbaLineService.exportTechCapacityExcel(pcbaLineIds);
    }

    @PostMapping("/exportLineExcel")
    public Result exportLineExcel(String searchPcbaLineName, Integer pcbaCompanyId, Integer pcbaWorkshopId, Integer pcbaProcessId) {
        return pcbaLineService.exportLineExcel(searchPcbaLineName, pcbaCompanyId, pcbaWorkshopId, pcbaProcessId);
    }

    @PostMapping("/exportLineExcelByType")
    public Result exportLineExcelByType(Integer type, String pcbaLineIds) {
        return pcbaLineService.exportLineExcelByType(type, pcbaLineIds);
    }

    @PostMapping("/auditPcbaLineTechDeclare")
    public Result auditPcbaLineTechDeclare(String paramsNotesDeclare, Integer pcbaLineId, Integer paramsStatusDeclare) {
        return pcbaLineService.auditPcbaLineTechDeclare(paramsNotesDeclare, pcbaLineId, paramsStatusDeclare);
    }

    @PostMapping("/auditPcbaLineTechActual")
    public Result auditPcbaLineTechActual(String paramsNotesActual, Integer pcbaLineId, Integer paramsStatusActual) {
        return pcbaLineService.auditPcbaLineTechActual(paramsNotesActual, pcbaLineId, paramsStatusActual);
    }

    @PostMapping("/copyLine")
    public Result copyLine(String pcbaLineIds) {
        return pcbaLineService.copyLine(pcbaLineIds);
    }

    @PostMapping("/getAllSmtLineForPcbaByCompany")
    public Result getAllSmtLineForPcbaByCompany(Integer pcbaCompanyId) {
        return pcbaLineService.getAllSmtLineForPcbaByCompany(pcbaCompanyId);
    }

    @PostMapping("/auditPcbaLineParamBase")
    public Result auditPcbaLineParamBase(Integer pcbaLineId, Integer paramsStatusBase, String paramsRemarkBase) {
        return pcbaLineService.auditPcbaLineParamBase(pcbaLineId, paramsStatusBase, paramsRemarkBase);
    }

    @PostMapping("/getAllNeedToLoopCloseLine")
    public Result getAllNeedToLoopCloseLine(@RequestBody String data) {
        return pcbaLineService.getAllNeedToLoopCloseLine(data);
    }

    @PostMapping("/getAllNeedToAgeCloseLine")
    public Result getAllNeedToAgeCloseLine(@RequestBody String data) {
        return pcbaLineService.getAllNeedToAgeCloseLine(data);
    }

    @PostMapping("/exportPcbaLineAndDeviceParamsExcel")
    public Result exportPcbaLineAndDeviceParamsExcel(String pcbaLineIds, Integer type, String operateType) {
        return pcbaLineService.exportPcbaLineAndDeviceParamsExcel(pcbaLineIds, type, operateType);
    }

    @PostMapping("/importPcbaLineAndDeviceParamsExcel")
    public Result importPcbaLineAndDeviceParamsExcel(MultipartFile file) {
        return pcbaLineService.importPcbaLineAndDeviceParamsExcel(file);
    }

    @PostMapping("/updateLineStatusByDevicesStatus")
    public Result updateLineStatusByDevicesStatus(Integer pcbaLineId) {
        return pcbaLineService.updateLineStatusByDevicesStatus(pcbaLineId);
    }

    @PostMapping("/getAllNeedToLoopCloseLineWaitAudit")
    public Result getAllNeedToLoopCloseLineWaitAudit(@RequestBody String data) {
        return pcbaLineService.getAllNeedToLoopCloseLineWaitAudit(data);
    }

    @PostMapping("/getAllNeedToAgeCloseLineWaitAudit")
    public Result getAllNeedToAgeCloseLineWaitAudit(@RequestBody String data) {
        return pcbaLineService.getAllNeedToAgeCloseLineWaitAudit(data);
    }
}
